package org.bing.engine.controller.lifecycle;

import org.bing.engine.controller.preference.PreferenceManager;
import org.bing.engine.controller.service.LocalControllerManager;
import org.bing.engine.controller.service.LocalInstanceManager;
import org.bing.engine.core.domain.Console;
import org.bing.engine.core.domain.Controller;
import org.bing.engine.core.domain.ControllerGroup;
import org.bing.engine.core.service.AbstractControllerLifecycle;

public class GeneralControllerLifecycle extends AbstractControllerLifecycle {
    private LocalControllerManager controllerManager;
    private LocalInstanceManager instanceManager;
    private PreferenceManager preference; 
    
    public void setControllerManager(LocalControllerManager mgr) {
        this.controllerManager = mgr;
    }

    public void setInstanceManager(LocalInstanceManager mgr) {
        this.instanceManager = mgr;
    }

    public void setPreferenceManager(PreferenceManager manager) {
        this.preference = manager;
    }
 
    @Override
    public void join(Console console, ControllerGroup group) {
        // store console/group info into local
        preference.saveTargetConsole(console);
        preference.saveTargetGroup(group); 
        Controller controller = controllerManager.localController();
        instanceManager.save(controller);
    }
}
